/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "虚拟体物体构建.h"

#include <Context/当前默认操作数据.h>
#include <core/shader_line.h>
#include <面/面.h>



S_物体* f_node_创建虚拟体(S_设备环境& ctx) {
	S_物体* ob = f_ob_创建(ctx, E_物体类型::t_虚拟体);
	//f_ob_创建矩阵(ob);
	ob->m_视口显示模式 = E_物体视口显示::e_OVS_边框 | E_物体视口显示::e_OVS_边 | E_物体视口显示::e_OVS_轮廓 | E_物体视口显示::e_OVS_面;
	ob->m_视口显示模式 |= ob->m_视口显示模式 << 16;

	ob->m_是否实例 = false;
	return ob;
}

S_物体* f_node_创建物理虚拟体(S_设备环境& ctx) {
	S_物体* ob = f_ob_创建(ctx, E_物体类型::t_物理几何虚拟体);
	ob->m_是否实例 = false;
	return ob;
}

S_物体* f_node_创建区域光虚拟体(S_设备环境& ctx) {
	S_物体* ob = f_ob_创建(ctx, E_物体类型::t_区域光);
	ob->m_视口显示模式 = 1 | 2 | 4 | 8;
	ob->m_视口显示模式 |= ob->m_视口显示模式 << 16;
	return ob;
}

S_物体* f_node_创建点光源虚拟体(S_设备环境& ctx) {
	S_物体* ob = f_ob_创建(ctx, E_物体类型::t_点光源);
	ob->m_视口显示模式 = E_物体视口显示::e_OVS_轮廓 | E_物体视口显示::e_OVS_面;
	ob->m_视口显示模式 |= ob->m_视口显示模式 << 16;
	return ob;
}

S_物体* f_node_创建平行光虚拟体(S_设备环境& ctx) {
	S_物体* ob = f_ob_创建(ctx, E_物体类型::t_平行光);
	//f_ob_创建矩阵(ob);
	ob->m_视口显示模式 = E_物体视口显示::e_OVS_边框 | E_物体视口显示::e_OVS_边 | E_物体视口显示::e_OVS_轮廓 | E_物体视口显示::e_OVS_面;
	ob->m_视口显示模式 |= ob->m_视口显示模式 << 16;

	ob->m_是否实例 = false;
	return ob;
}

void f_node_销毁虚拟体(S_物体* ob) {
	f_surface_销毁网格(f_ob_getMesh(ob));

	f_ob_销毁(ob);
}


S_Mesh* f_node_虚拟体网格创建_摄像机锥形(S_设备环境& ctx) {
	S_Mesh* me = f_surface_创建网格对象(0, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);

	std::vector<S_VNT1> 顶点;

	float32 r = 0.5;
	顶点.push_back({ {0, 0, 0}, {}, {} });
	顶点.push_back({ {-0.5f, 0.5f, r}, {}, {} });
	顶点.push_back({ {0.5f, 0.5f, r}, {}, {} });
	顶点.push_back({ {-0.5f, -0.5f, r}, {}, {} });
	顶点.push_back({ {0.5f, -0.5f, r}, {}, {} });
	
	顶点.push_back({ {-0.3f, 0.52f, r}, {}, {} });
	顶点.push_back({ {0.0f, 0.8f, r}, {}, {} });
	顶点.push_back({ {0.3f, 0.52f, r}, {}, {} });

	std::vector<uint32> 索引;
	索引 = {0,1, 0,2, 0,3, 0,4,  1,2, 2,4, 4,3, 3,1,  5,6, 6,7, 7,5};


	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);

	f_mesh_set绘制内存属性(me, {});
	
	return me;
}

S_Mesh* f_node_虚拟体网格创建_铰链轴(S_设备环境& ctx) {
	uint32 圆细分数量 = 32;
	uint32 半圆细分数量 = 圆细分数量 >> 1;
	std::vector<vec2> 圆顶点(圆细分数量);
	f_graph_计算圆坐标XY({}, 0.5, 圆细分数量, 圆顶点.data());


	std::vector<S_VNT1> 顶点;
	std::vector<uint32> 索引;

	for (uint32 i = 0; i < 圆细分数量; ++i) {
		顶点.push_back({ {-0.5f, 圆顶点[i].x, 圆顶点[i].y}, {0.4f,0.4f,1}, {}});
		索引.push_back(i);
		索引.push_back(i+1);
	}
	索引.back() = 0;

	for (uint32 i = 0; i < 圆细分数量; ++i) {
		顶点.push_back({ {0.5f, 圆顶点[i].x, 圆顶点[i].y}, {0.4f,0.4f,1}, {} });
		索引.push_back(圆细分数量 + i);
		索引.push_back(圆细分数量 + i + 1);
	}
	索引.back() = 圆细分数量;

	顶点.push_back({ {-0.5f, 0, 0}, {0.4f,0.4f,1}, {} });
	顶点.push_back({ {0.5f, 0, 0}, {0.4f,0.4f,1}, {} });
	索引.push_back(圆细分数量*2);
	索引.push_back(圆细分数量*2+1);

	

	S_Mesh* me = f_surface_创建网格对象(0, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	me->m_Color = {60,60,255,255};
	return me;
}

S_Mesh* f_node_虚拟体网格创建_立方体(S_设备环境& ctx) {
	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);

	std::vector<S_VNTC> 顶点;
	std::vector<uint32> 索引;
	f_graph_立方体线段(顶点, 索引, { 1,1,1 }, { 0,0,0 });

	f_me_fill顶点(me, 顶点);
	f_me_fill索引(me, 索引);
	f_mesh_计算包围盒(me);

	return me;
}

S_Mesh* f_node_虚拟体网格创建_圆柱体(S_设备环境& ctx) {
	S_Mesh* me = f_surface_创建网格对象(0, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);

	uint32 圆细分数量 = 32;
	std::vector<vec2> 圆顶点(圆细分数量);
	f_graph_计算圆坐标XY({}, 0.5, 圆细分数量, 圆顶点.data());


	std::vector<S_VNT1> 顶点;
	std::vector<uint32> 索引;

	顶点.push_back({ {0.5f, 0, 0}, {0,1,0}, {} });
	顶点.push_back({ {0.5f, 0, 0}, {0,-1,0}, {} });
	顶点.push_back({ {-0.5f, 0, 0}, {0,1,0}, {} });
	顶点.push_back({ {-0.5f, 0, 0}, {0,-1,0}, {} });
	索引.push_back(0); 索引.push_back(1); 
	索引.push_back(2); 索引.push_back(3);

	顶点.push_back({ {0, 0, -0.5f}, {0,1,0}, {} });
	顶点.push_back({ {0, 0, -0.5f}, {0,-1,0}, {} });
	顶点.push_back({ {0, 0, 0.5f}, {0,-1,0}, {} });
	顶点.push_back({ {0, 0, 0.5f}, {0,1,0}, {} });
	索引.push_back(4); 索引.push_back(5);
	索引.push_back(6); 索引.push_back(7); 

	
	for (uint32 i = 0; i < 圆细分数量; ++i) {
		顶点.push_back({{ 圆顶点[i].x, 0, 圆顶点[i].y}, {0,1,0}, {}});
		索引.push_back(8 + i);
		索引.push_back(8 + i + 1);
	}
	索引.back() = 8;

	for (uint32 i = 0; i < 圆细分数量; ++i) {
		顶点.push_back({ { 圆顶点[i].x, 0, 圆顶点[i].y}, {0,-1,0}, {} });
		索引.push_back(8 + 圆细分数量 + i);
		索引.push_back(8 + 圆细分数量 + i + 1);
	}
	索引.back() = 8 + 圆细分数量;


	me->m_Color = S_RGBA8UI{60,255,60,255};

	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	return me;
}

S_Mesh* f_node_虚拟体网格创建_球体(S_设备环境& ctx) {
	S_Mesh* me = f_surface_创建网格对象(0, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	//f_mesh_gen网格元素绘制属性(me, 1);

	uint32 圆细分数量 = 32;
	std::vector<vec2> 圆顶点(圆细分数量);
	f_graph_计算圆坐标XY({}, 0.5, 圆细分数量, 圆顶点.data());

	std::vector<S_VNT1> 顶点;
	std::vector<uint32> 索引;

	for (uint32 i = 0; i < 圆细分数量; ++i) {
		顶点.push_back({ { 圆顶点[i].x, 0, 圆顶点[i].y}, {}, {} });
		索引.push_back(i);
		索引.push_back(i + 1);
	}
	索引.back() = 0;

	for (uint32 i = 0; i < 圆细分数量; ++i) {
		顶点.push_back({ { 圆顶点[i].x, 圆顶点[i].y, 0}, {}, {} });
		索引.push_back(圆细分数量 + i);
		索引.push_back(圆细分数量 + i + 1);
	}
	索引.back() = 圆细分数量;

	for (uint32 i = 0; i < 圆细分数量; ++i) {
		顶点.push_back({ { 0, 圆顶点[i].x, 圆顶点[i].y}, {}, {} });
		索引.push_back(圆细分数量*2 + i);
		索引.push_back(圆细分数量*2 + i + 1);
	}
	索引.back() = 圆细分数量*2;


	me->m_Color = S_RGBA8UI{ 60,255,60,255 };

	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	return me;
}

S_Mesh* f_node_虚拟体网格创建_平面(S_设备环境& ctx) {
	S_Mesh* me = f_surface_创建网格对象(0, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	//f_mesh_gen网格元素绘制属性(me, 1);

	uint32 圆细分数量 = 32;

	std::vector<S_VNT1> 顶点;
	std::vector<uint32> 索引;

	顶点.push_back({ { -0.5, 0, -0.5}, {}, {} });
	顶点.push_back({ { 0.5, 0, -0.5}, {}, {} });
	顶点.push_back({ { 0.5, 0, 0.5}, {}, {} });
	顶点.push_back({ { -0.5, 0, 0.5}, {}, {} });
	索引.push_back(0); 索引.push_back(1);
	索引.push_back(1); 索引.push_back(2);
	索引.push_back(2); 索引.push_back(3);
	索引.push_back(3); 索引.push_back(0);
	
	顶点.push_back({ { 0, 0, 0}, {}, {} });
	顶点.push_back({ { 0.3f, 0.3f, 0}, {}, {} });
	顶点.push_back({ { -0.3f, 0.3f, 0}, {}, {} });
	索引.push_back(4); 索引.push_back(5);
	索引.push_back(4); 索引.push_back(6);


	me->m_Color = S_RGBA8UI{ 60,255,60,255 };

	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	return me;
}

S_Mesh* f_node_虚拟体网格创建_胶囊(S_设备环境& ctx) {
	uint32 圆细分数量 = 32;
	uint32 半圆细分数量 = 圆细分数量>>1;
	std::vector<vec2> 圆顶点(圆细分数量);
	f_graph_计算圆坐标XY({}, 0.5, 圆细分数量, 圆顶点.data());

	uint32 offsetID = 0;

	std::vector<S_VNT1> 顶点;
	std::vector<uint32> 索引;
	for (uint32 i = 0; i < 圆细分数量; ++i) {
		auto& v = 圆顶点[i];
		顶点.push_back({ {v.x, 0, v.y}, {0,1,0}, {} });
		索引.push_back(i);
		索引.push_back(i+1);
	}
	索引.back() = 0;

	offsetID = 圆细分数量;
	for (uint32 i = 0; i < 半圆细分数量; ++i) {
		auto& v = 圆顶点[i];
		顶点.push_back({ {0, v.y, v.x}, {0,1,0}, {} });
		索引.push_back(i + offsetID);
		索引.push_back(i + offsetID + 1);
	}
	顶点.push_back({ {0, 圆顶点[半圆细分数量].y, 圆顶点[半圆细分数量].x}, {0,1,0}, {}});
	
	offsetID = 顶点.size();
	for (uint32 i = 0; i < 半圆细分数量; ++i) {
		auto& v = 圆顶点[i];
		顶点.push_back({ {v.x, v.y, 0}, {0,1,0}, {} });
		索引.push_back(i + offsetID);
		索引.push_back(i + offsetID + 1);
	}
	顶点.push_back({ {圆顶点[半圆细分数量].x, 圆顶点[半圆细分数量].y, 0}, {0,1,0}, {} });
	



	offsetID = 顶点.size();
	for (uint32 i = 0; i < 圆细分数量; ++i) {
		auto& v = 圆顶点[i];
		顶点.push_back({ {v.x, 0, v.y}, {0,-1,0}, {} });
		索引.push_back(i + offsetID);
		索引.push_back(i + offsetID + 1);
	}
	索引.back() = offsetID;
	
	offsetID = 顶点.size();
	for (uint32 i = 0; i < 半圆细分数量; ++i) {
		auto& v = 圆顶点[i];
		顶点.push_back({ {0, -v.y, v.x}, {0,-1,0}, {} });
		索引.push_back(i + offsetID);
		索引.push_back(i + offsetID + 1);
	}
	顶点.push_back({ {0, -圆顶点[半圆细分数量].y, 圆顶点[半圆细分数量].x}, {0,-1,0}, {} });
	
	offsetID = 顶点.size();
	for (uint32 i = 0; i < 半圆细分数量; ++i) {
		auto& v = 圆顶点[i];
		顶点.push_back({ {v.x, -v.y, 0}, {0,-1,0}, {} });
		索引.push_back(i + offsetID);
		索引.push_back(i + offsetID + 1);
	}
	顶点.push_back({ {圆顶点[半圆细分数量].x, -圆顶点[半圆细分数量].y, 0}, {0,-1,0}, {} });
	


	offsetID = 顶点.size();
	顶点.push_back({ {-0.5f, 0, 0}, {0,-1,0}, {} });
	顶点.push_back({ {-0.5f, 0, 0}, {0,1,0}, {} });
	索引.push_back(offsetID + 0);
	索引.push_back(offsetID + 1);

	顶点.push_back({ {0.5f, 0, 0}, {0,-1,0}, {} });
	顶点.push_back({ {0.5f, 0, 0}, {0,1,0}, {} });
	索引.push_back(offsetID + 2);
	索引.push_back(offsetID + 3);

	顶点.push_back({ {0, 0, -0.5f}, {0,-1,0}, {} });
	顶点.push_back({ {0, 0, -0.5f}, {0,1,0}, {} });
	索引.push_back(offsetID + 4);
	索引.push_back(offsetID + 5);

	顶点.push_back({ {0, 0, 0.5f}, {0,-1,0}, {} });
	顶点.push_back({ {0, 0, 0.5f}, {0,1,0}, {} });
	索引.push_back(offsetID + 6);
	索引.push_back(offsetID + 7);



	S_Mesh* me = f_surface_创建网格对象(0, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	return me;
}

S_Mesh* f_node_虚拟体网格创建_链接线(S_设备环境& ctx) {
	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);

	std::vector<S_VNT1> 顶点;
	顶点 = {{0,0,0}, {1,1,1}};

	std::vector<uint32> 索引;
	索引 = { 0, 1 };

	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);

	f_mesh_set绘制内存属性(me, {});

	return me;
}

S_Mesh* f_node_虚拟体网格创建_灯光圆(S_设备环境& ctx) {
	uint32 圆细分数量 = 32;
	std::vector<vec2> 圆顶点(圆细分数量);
	f_graph_计算圆坐标XY({}, 0.5, 圆细分数量, 圆顶点.data());

	std::vector<S_VNT1> 顶点;
	for (auto& e : 圆顶点) {
		顶点.push_back({{e.x * 0.6f, e.y * 0.6f, 0}, {}, {}});
	}
	for (auto& e : 圆顶点) {
		顶点.push_back({ {e.x, e.y, 0}, {}, {} });
	}

	std::vector<uint32> 索引;
	for (uint32 i = 0; i < 31; i+=2) {
		索引.push_back(i);
		索引.push_back(i + 1);
	}

	for (uint32 i = 0; i < 31; ++i) {
		索引.push_back(i+32);
		索引.push_back(i + +33);
	}
	索引.push_back(63);
	索引.push_back(32);

	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	//f_surface_计算包围盒(me);
	return me;
}

S_Mesh* f_node_虚拟体网格创建_灯光平行线(S_设备环境& ctx) {
	vec3 平行光线条1 = { 0.5f * sin(M_PI * 0.5 * 0.2), -0.5f * cos(M_PI * 0.5 * 0.2), 0 };
	vec3 平行光线条2 = { 0.5f * sin(M_PI * 0.5 * 0.5), -0.5f * cos(M_PI * 0.5 * 0.5), 0 };
	vec3 平行光线条3 = { 0.5f * sin(M_PI * 0.5), -0.5f * cos(M_PI * 0.5), 0 };

	std::vector<S_VNT1> 顶点;
	顶点.push_back({ 平行光线条1, {}, {} });
	顶点.push_back({ {平行光线条1.x, -4, 0}, {}, {}});

	顶点.push_back({ 平行光线条2, {}, {} });
	顶点.push_back({ {平行光线条2.x, -4, 0}, {}, {} });

	顶点.push_back({ 平行光线条3, {}, {} });
	顶点.push_back({ {平行光线条3.x, -4, 0}, {}, {} });


	顶点.push_back({ {-平行光线条1.x, 平行光线条1.y, 0}, {}, {} });
	顶点.push_back({ {-平行光线条1.x, -4, 0}, {}, {} });

	顶点.push_back({ {-平行光线条2.x, 平行光线条2.y, 0}, {}, {} });
	顶点.push_back({ {-平行光线条2.x, -4, 0}, {}, {} });

	顶点.push_back({ {-平行光线条3.x, 平行光线条3.y, 0}, {}, {} });
	顶点.push_back({ {-平行光线条3.x, -4, 0}, {}, {} });


	std::vector<uint32> 索引;
	for (uint32 i = 0; i < 12; ++i) {
		索引.push_back(i);
	}

	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	//f_surface_计算包围盒(me);
	return me;
}

S_Mesh* f_node_虚拟体网格创建_区域光四边线(S_设备环境& ctx) {
	std::vector<S_VNT1> 顶点;
	顶点.push_back({ {-1,-1,0}, {}, {} });
	顶点.push_back({ {1,-1,0}, {}, {} });
	顶点.push_back({ {1,1,0}, {}, {} });
	顶点.push_back({ {-1,1,0}, {}, {} });

	顶点.push_back({ {0, 0, 0}, {}, {} });
	顶点.push_back({ {0, 0, -1}, {}, {} });

	std::vector<uint32> 索引 = {0,1, 1,2, 2,3, 3,0, 4,5};
	

	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	return me;
}

S_Mesh* f_node_虚拟体网格创建_四边线(S_设备环境& ctx) {
	std::vector<S_VNT1> 顶点;
	顶点.push_back({ {-1,-1,0}, {}, {} });
	顶点.push_back({ {1,-1,0}, {}, {} });
	顶点.push_back({ {1,1,0}, {}, {} });
	顶点.push_back({ {-1,1,0}, {}, {} });

	std::vector<uint32> 索引 = { 0,1, 1,2, 2,3, 3,0 };

	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	return me;
}

S_Mesh* f_node_虚拟体网格创建_十字叉(S_设备环境& ctx) {
	std::vector<S_VNT1> 顶点;
	顶点.push_back({ {-0.5f, 0, 0}, {}, {} });
	顶点.push_back({ {0.5f, 0, 0}, {}, {} });

	顶点.push_back({ {0, -0.5f, 0}, {}, {} });
	顶点.push_back({ {0, 0.5f, 0}, {}, {} });

	顶点.push_back({ {0, 0, -0.5f}, {}, {} });
	顶点.push_back({ {0, 0, 0.5f}, {}, {} });

	std::vector<uint32> 索引 = { 0,1, 2,3, 4,5 };


	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);

	f_mesh_计算包围盒(me);
	return me;
}

S_Mesh* f_node_虚拟体网格创建_范围圆(S_设备环境& ctx) {
	uint32 圆细分数量 = 32;
	std::vector<vec2> 圆顶点(圆细分数量);
	f_graph_计算圆坐标XY({}, 0.5, 圆细分数量, 圆顶点.data());

	std::vector<S_VNT1> 顶点;
	for (auto& e : 圆顶点) {
		顶点.push_back({ {e.x, e.y, 0}, {}, {} });
	}
	for (auto& e : 圆顶点) {
		顶点.push_back({ {e.x, 0, e.y}, {}, {} });
	}
	for (auto& e : 圆顶点) {
		顶点.push_back({ {0, e.x, e.y}, {}, {} });
	}

	uint32 段数 = 圆细分数量 - 1;

	std::vector<uint32> index;
	for (uint32 i = 0; i < 段数; ++i) {
		index.push_back(i);
		index.push_back(i + 1);
	}
	index.push_back(段数);
	index.push_back(0);


	段数 = index.size();
	std::vector<uint32> 索引;
	for (uint32 k = 0; k < 3; ++k) {
		for (uint32 i = 0; i < 段数; ++i) {
			索引.push_back(index[i] + 圆细分数量*k);
		}
	}


	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	f_mesh_计算包围盒(me);
	return me;
}


S_Mesh* f_node_虚拟体网格创建_胶囊封套端(S_设备环境& ctx) {
	uint32 圆细分数量 = 32;
	std::vector<vec2> 圆顶点(圆细分数量);
	f_graph_计算圆坐标XY({}, 1, 圆细分数量, 圆顶点.data());

	std::vector<S_VNT1> 顶点;
	for (auto& e : 圆顶点) {
		顶点.push_back({ {e.x, e.y, 0}, {1,0,0}, {} });
	}
	//for (auto& e : 圆顶点) {
	//	顶点.push_back({ {e.x, e.y, 1}, {0,0,1}, {} });
	//}

	for (uint32 i = 0; i <= 16; ++i) {
		auto& v = 圆顶点[i];
		顶点.push_back({ {v.x, 0, v.y}, {0,0,1}, {} });
	}
	for (uint32 i = 0; i <= 16; ++i) {
		auto& v = 圆顶点[i];
		顶点.push_back({ {0, v.x, v.y}, {0,0,1}, {} });
	}
	

	std::vector<uint32> 索引;
	for (uint32 i = 0; i < 圆细分数量; ++i) {
		索引.push_back(i);
	}
	索引.push_back(0);
	索引.push_back(0xffffffff);

	for (uint32 i = 0; i <= 16; ++i) {
		索引.push_back(i + 圆细分数量);
	}
	索引.push_back(0xffffffff);
	for (uint32 i = 0; i <= 16; ++i) {
		索引.push_back(i + 圆细分数量 + 17);
	}

	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);
	f_mesh_set绘制内存属性(me, {});
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	f_mesh_计算包围盒(me);

	return me;
}

S_Mesh* f_node_虚拟体网格创建_胶囊封套管(S_设备环境& ctx) {
	std::vector<S_VNT1> 顶点;

	顶点.push_back({ {1, 0, 0}, {1,0,0}, {} });
	顶点.push_back({ {0, 1, 0}, {1,0,0}, {} });
	顶点.push_back({ {-1, 0, 0}, {1,0,0}, {} });
	顶点.push_back({ {0, -1, 0}, {1,0,0}, {} });
	

	顶点.push_back({ {1, 0, 0}, {1,0,0}, {} });
	顶点.push_back({ {0, 1, 0}, {1,0,0}, {} });
	顶点.push_back({ {-1, 0, 0}, {1,0,0}, {} });
	顶点.push_back({ {0, -1, 0}, {1,0,0}, {} });
	

	顶点.push_back({ {1, 0, 0}, {0,0,1}, {} });
	顶点.push_back({ {0, 1, 0}, {0,0,1}, {} });
	顶点.push_back({ {-1, 0, 0}, {0,0,1}, {} });
	顶点.push_back({ {0, -1, 0}, {0,0,1}, {} });


	顶点.push_back({ {1, 0, 0}, {0,0,1}, {} });
	顶点.push_back({ {0, 1, 0}, {0,0,1}, {} });
	顶点.push_back({ {-1, 0, 0}, {0,0,1}, {} });
	顶点.push_back({ {0, -1, 0}, {0,0,1}, {} });


	//顶点.push_back({ {0.5f, 0, 1}, {1,1,1}, {} });
	//顶点.push_back({ {0, 0.5f, 1}, {1,1,1}, {} });
	//顶点.push_back({ {-0.5f, 0, 1}, {1,1,1}, {} });
	//顶点.push_back({ {0, -0.5f, 1}, {1,1,1}, {} });
	//
	//顶点.push_back({ {0.5f, 0, 1}, {1,1,1}, {} });
	//顶点.push_back({ {0, 0.5f, 1}, {1,1,1}, {} });
	//顶点.push_back({ {-0.5f, 0, 1}, {1,1,1}, {} });
	//顶点.push_back({ {0, -0.5f, 1}, {1,1,1}, {} });



	std::vector<uint32> 索引;
	索引.push_back(0); 索引.push_back(4);
	索引.push_back(1); 索引.push_back(5);
	索引.push_back(2); 索引.push_back(6);
	索引.push_back(3); 索引.push_back(7);

	索引.push_back(8); 索引.push_back(12);
	索引.push_back(9); 索引.push_back(13);
	索引.push_back(10); 索引.push_back(14);
	索引.push_back(11); 索引.push_back(15);

	
	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);
	f_mesh_set绘制内存属性(me, {});
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	f_mesh_计算包围盒(me);

	return me;
}

S_Mesh* f_node_虚拟体网格创建_边界框(S_设备环境& ctx) {
	std::vector<S_VNT1> 顶点;
	float32 size = 0.5;
	float32 长度 = 0.15;
	
	//-x -y -z
	顶点.push_back({ {-size, -size, -size}, {1,0,0}, {} });
	顶点.push_back({ {-size + 长度, -size, -size}, {1,0,0}, {} });
	顶点.push_back({ {-size, -size + 长度, -size}, {1,0,0}, {} });
	顶点.push_back({ {-size, -size, -size + 长度}, {1,0,0}, {} });
	//-x y -z
	顶点.push_back({ {-size, size, -size}, {1,0,0}, {} });
	顶点.push_back({ {-size + 长度, size, -size}, {1,0,0}, {} });
	顶点.push_back({ {-size, size - 长度, -size}, {1,0,0}, {} });
	顶点.push_back({ {-size, size, -size + 长度}, {1,0,0}, {} });
	//x y -z
	顶点.push_back({ {size, size, -size}, {1,0,0}, {} });
	顶点.push_back({ {size - 长度, size, -size}, {1,0,0}, {} });
	顶点.push_back({ {size, size - 长度, -size}, {1,0,0}, {} });
	顶点.push_back({ {size, size, -size + 长度}, {1,0,0}, {} });
	//x -y -z
	顶点.push_back({ {size, -size, -size}, {1,0,0}, {} });
	顶点.push_back({ {size - 长度, -size, -size}, {1,0,0}, {} });
	顶点.push_back({ {size, -size + 长度, -size}, {1,0,0}, {} });
	顶点.push_back({ {size, -size, -size + 长度}, {1,0,0}, {} });

	//-x -y z
	顶点.push_back({ {-size, -size, size}, {1,0,0}, {} });
	顶点.push_back({ {-size + 长度, -size, size}, {1,0,0}, {} });
	顶点.push_back({ {-size, -size + 长度, size}, {1,0,0}, {} });
	顶点.push_back({ {-size, -size, size - 长度}, {1,0,0}, {} });
	//-x y z
	顶点.push_back({ {-size, size, size}, {1,0,0}, {} });
	顶点.push_back({ {-size + 长度, size, size}, {1,0,0}, {} });
	顶点.push_back({ {-size, size - 长度, size}, {1,0,0}, {} });
	顶点.push_back({ {-size, size, size - 长度}, {1,0,0}, {} });
	//x y z
	顶点.push_back({ {size, size, size}, {1,0,0}, {} });
	顶点.push_back({ {size - 长度, size, size}, {1,0,0}, {} });
	顶点.push_back({ {size, size - 长度, size}, {1,0,0}, {} });
	顶点.push_back({ {size, size, size - 长度}, {1,0,0}, {} });
	//x -y z
	顶点.push_back({ {size, -size, size}, {1,0,0}, {} });
	顶点.push_back({ {size - 长度, -size, size}, {1,0,0}, {} });
	顶点.push_back({ {size, -size + 长度, size}, {1,0,0}, {} });
	顶点.push_back({ {size, -size, size - 长度}, {1,0,0}, {} });


	std::vector<uint32> 索引 = {
		0,1, 0,2, 0,3,
		4,5, 4,6, 4,7,
		8,9, 8,10, 8,11,
		12,13, 12,14, 12,15,

		16,17, 16,18, 16,19,
		20,21, 20,22, 20,23,
		24,25, 24,26, 24,27,
		28,29, 28,30, 28,31,
	};
	

	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_gen网格元素绘制属性(me, 1);
	f_mesh_set绘制内存属性(me, {});
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	f_mesh_计算包围盒(me);

	return me;
}

S_Mesh* f_node_虚拟体网格创建_箭头(S_设备环境& ctx, E_轴向 方向) {
	std::vector<S_VNT1> 顶点;
	std::vector<uint32> 索引;

	const float32 箭头大小 = 0.05;
	const float32 箭身高度 = 0.75;
	switch (方向) {
		case E_轴向::e_X: {
			顶点.push_back({ {0,0,0}, {}, {} });
			顶点.push_back({ {箭身高度,0,0}, {}, {} });

			顶点.push_back({ {0.75,-箭头大小,-箭头大小}, {}, {} });
			顶点.push_back({ {0.75,-箭头大小,箭头大小}, {}, {} });
			顶点.push_back({ {0.75,箭头大小,箭头大小}, {}, {} });
			顶点.push_back({ {0.75,箭头大小,-箭头大小}, {}, {} });

			顶点.push_back({ {0.1,0,0}, {}, {} });
			break;
		}
		case E_轴向::e_Y: {
			顶点.push_back({ {0,0,0}, {}, {} });
			顶点.push_back({ {0,箭身高度,0}, {}, {} });

			顶点.push_back({ {-箭头大小,0.75,-箭头大小}, {}, {} });
			顶点.push_back({ {-箭头大小,0.75,箭头大小}, {}, {} });
			顶点.push_back({ {箭头大小,0.75,箭头大小}, {}, {} });
			顶点.push_back({ {箭头大小,0.75,-箭头大小}, {}, {} });

			顶点.push_back({ {0,1,0}, {}, {} });
			break;
		}
		case E_轴向::e_Z: {
			顶点.push_back({ {0,0,0}, {}, {} });
			顶点.push_back({ {0,0,箭身高度}, {}, {} });

			顶点.push_back({ {-箭头大小,-箭头大小,0.75}, {}, {} });
			顶点.push_back({ {-箭头大小,箭头大小,0.75}, {}, {} });
			顶点.push_back({ {箭头大小,箭头大小,0.75}, {}, {} });
			顶点.push_back({ {箭头大小,-箭头大小,0.75}, {}, {} });

			顶点.push_back({ {0,0,1}, {}, {} });
			break;
		}
		default:
			break;
	}
	

	索引 = {0,1,   2,3, 3,4, 4,5, 5,2,   2,6, 3,6, 4,6, 5,6};

	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_set绘制内存属性(me, {});
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	f_mesh_计算包围盒(me);
	return me;
}

S_Mesh* f_node_虚拟体网格创建_旋转箭头(S_设备环境& ctx, E_轴向 方向) {
	std::vector<S_VNT1> 顶点;
	std::vector<uint32> 索引;

	
	std::vector<vec2> 圆坐标(36);
	f_graph_计算圆坐标XY({}, 0.5, 36, 圆坐标.data(), 360);

	for (uint32 i = 0; i < 36; ++i) {
		switch (方向) {
			case E_轴向::e_X: {
				顶点.push_back({ _Vec3(0, 圆坐标[i].x, 圆坐标[i].y) * (i / 36.0), {}, {} });
				break;
			}
			case E_轴向::e_Y: {
				顶点.push_back({ _Vec3(圆坐标[i].x, 0, 圆坐标[i].y) * (i / 36.0), {}, {} });
				break;
			}
			case E_轴向::e_Z: {
				顶点.push_back({ _Vec3(圆坐标[i].x, 圆坐标[i].y, 0) * (i / 36.0), {}, {} });
				break;
			}
			default:
				break;
		}

		索引.push_back(i);
		索引.push_back(i+1);
	}
	
	switch (方向) {
		case E_轴向::e_X: {
			顶点.push_back({ {0, 圆坐标[0].x, 圆坐标[0].y}, {}, {} });
			break;
		}
		case E_轴向::e_Y: {
			顶点.push_back({ {圆坐标[0].x, 0, 圆坐标[0].y}, {}, {} });
			break;
		}
		case E_轴向::e_Z: {
			顶点.push_back({ {圆坐标[0].x, 圆坐标[0].y, 0}, {}, {} });
			break;
		}
		default:
			break;
	}

	S_Mesh* me = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_mesh_set绘制内存属性(me, {});
	f_mesh_fill顶点数据(me, 顶点);
	f_me_fill索引(me, 索引);
	f_mesh_计算包围盒(me);
	return me;
}


void f_node_虚拟体_设置摄像机虚拟网格(S_物体* ob, S_物体* 目标, S_摄像机* 摄像机, const vec3& loc) {
	S_Mesh* 锥形 = f_ob_getMesh(ob, 0);
	
	锥形->m_Color = S_节点UI主题::uic_摄像机虚拟体;
	S_MeshTranformProp& 锥形变换属性 = f_buf_网格元素变换属性_at(锥形->m_网格元素变换属性, ob->m_实例ID);
	

	vec3 s = f_camera_计算摄像机以角度缩放大小(摄像机);
	锥形变换属性.m_XScale = 1;
	锥形变换属性.m_YScale = s.y;
	锥形变换属性.m_ZScale = s.z;
	锥形变换属性.m_TransformMode = DEF_MESH_LINE_TRANFORMTYPEMODEL_CenterZoom;
	
	锥形->m_线宽 = 2;
	f_mesh_计算包围盒(锥形);
	
	ob->m_isUpdate = true;


	if (目标) {
		S_Mesh* 视线 = f_ob_getMesh(目标, 1);
		S_MeshTranformProp& 视线变换属性 = f_buf_网格元素变换属性_at(视线->m_网格元素变换属性, ob->m_实例ID);

		视线变换属性.m_XScale = loc.x;
		视线变换属性.m_YScale = loc.y;
		视线变换属性.m_ZScale = loc.z;

		视线变换属性.m_TransformMode = DEF_MESH_LINE_TRANFORMTYPEMODEL_PointLink;
		视线->m_线宽 = 0.75;

		f_mesh_计算包围盒(视线);

		目标->m_isUpdate = true;
	}
	
}

void f_node_虚拟体_设置平行光虚拟网格(S_物体* ob) {
	S_Mesh* 灯光点 = f_ob_getMesh(ob, 0);
	S_Mesh* 灯光线 = f_ob_getMesh(ob, E_物体网格元素类型::e_MT_面);


	S_MeshTranformProp& 发光点变换属性 = f_buf_网格元素变换属性_at(灯光点->m_网格元素变换属性, ob->m_实例ID);
	发光点变换属性.m_TransformMode = DEF_MESH_TRANFORMTYPE_Mark | (DEF_MESH_Tranform_ViewSize << 16);
	发光点变换属性.m_Scale = 0.04;

	S_MeshTranformProp& 灯光线变换属性 = f_buf_网格元素变换属性_at(灯光线->m_网格元素变换属性, ob->m_实例ID);
	灯光线变换属性.m_TransformMode = DEF_MESH_LINE_TRANFORMTYPEMODEL_GAZE | (DEF_MESH_Tranform_ViewSize << 16);
	灯光线变换属性.m_Scale = 0.04;

	f_mesh_计算包围盒(灯光点);
	f_mesh_计算包围盒(灯光线);
}

void f_node_虚拟体_设置区域光虚拟网格(S_物体* ob) {
	S_Mesh* 发光区 = f_ob_getMesh(ob, 0);
	S_Mesh* 灯光点 = f_ob_getMesh(ob, 1);
	S_Mesh* 灯光边界线 = f_ob_getMesh(ob, 2);
	S_Mesh* 发光区边界线 = f_ob_getMesh(ob, 3);

	S_MeshTranformProp& 发光点变换属性 = f_buf_网格元素变换属性_at(灯光点->m_网格元素变换属性, ob->m_实例ID);
	发光点变换属性.m_TransformMode = DEF_MESH_TRANFORMTYPE_Mark | (DEF_MESH_Tranform_ViewSize << 16);
	发光点变换属性.m_Scale = 0.02;

	S_MeshTranformProp& 灯光线变换属性 = f_buf_网格元素变换属性_at(灯光边界线->m_网格元素变换属性, ob->m_实例ID);
	灯光线变换属性.m_TransformMode = DEF_MESH_LINE_TRANFORMTYPEMODEL_NONE;

	f_mesh_计算包围盒(灯光点);
	f_mesh_计算包围盒(灯光边界线);
	f_mesh_计算包围盒(发光区边界线);

	//auto* lp = f_ob_getLigth(ob);
	//S_LightArea& light = f_bm_at<S_LightArea>(lp->m_灯光数据, 0);

	//发光区->m_显示 = false;
}

void f_node_虚拟体_设置点光源虚拟网格(S_物体* ob) {
	S_Mesh* 灯光点 = f_ob_getMesh(ob, 0);
	S_Mesh* 灯光线 = f_ob_getMesh(ob, 1);


	S_MeshTranformProp& 发光点变换属性 = f_buf_网格元素变换属性_at(灯光点->m_网格元素变换属性, ob->m_实例ID);
	发光点变换属性.m_TransformMode = DEF_MESH_TRANFORMTYPE_Mark | (DEF_MESH_Tranform_ViewSize << 16);
	发光点变换属性.m_Scale = 0.02;

	S_MeshTranformProp& 灯光线变换属性 = f_buf_网格元素变换属性_at(灯光线->m_网格元素变换属性, ob->m_实例ID);
	灯光线变换属性.m_TransformMode = DEF_MESH_LINE_TRANFORMTYPEMODEL_NONE;


	f_mesh_计算包围盒(灯光点);
	f_mesh_计算包围盒(灯光线);
}

S_Mesh* f_node_虚拟体_设置十字叉虚拟网格(S_物体* ob, S_Mesh* me) {
	f_ob_set数据槽数量(ob, 1);
	me = f_surface_创建实例(me ? me : S_节点数据::g_me_十字叉);

	f_ob_set数据(ob, me);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质());
	f_ob_set线宽(ob, 1.5, 0);
	f_ob_set颜色2(ob, ob->m_颜色, 0);
	f_mesh_set绘制内存属性(f_ob_getMesh(ob, 0), {});
	f_mesh_计算包围盒(f_ob_getMesh(ob, 0));

	return me;
}

S_Mesh* f_node_虚拟体_设置立方体虚拟网格(S_物体* ob, S_Mesh* me) {
	auto om = f_ob_getMesh(ob);
	if(om) f_surface_销毁网格(om);
	me = f_surface_创建实例(me ? me : S_节点数据::g_me_立方体);

	f_ob_set数据槽数量(ob, 1);
	f_ob_set数据(ob, me);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质());
	f_ob_set线宽(ob, 1.0, 0);
	f_ob_set颜色2(ob, ob->m_颜色, 0);
	f_mesh_set绘制内存属性(f_ob_getMesh(ob, 0), {});
	f_mesh_计算包围盒(f_ob_getMesh(ob, 0));

	return me;
}

S_Mesh* f_node_虚拟体_设置圆柱体虚拟网格(S_物体* ob, S_Mesh* me) {
	auto om = f_ob_getMesh(ob);
	if (om) f_surface_销毁网格(om);
	me = f_surface_创建实例(me ? me : S_节点数据::g_me_圆柱体);

	f_ob_set数据槽数量(ob, 1);
	f_ob_set数据(ob, me);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质());
	f_ob_set线宽(ob, 1.0, 0);
	f_ob_set颜色2(ob, ob->m_颜色, 0);
	f_mesh_set绘制内存属性(f_ob_getMesh(ob, 0), {});
	f_mesh_计算包围盒(f_ob_getMesh(ob, 0));

	return me;
}

S_Mesh* f_node_虚拟体_设置球体虚拟网格(S_物体* ob, S_Mesh* me) {
	auto om = f_ob_getMesh(ob);
	if (om) f_surface_销毁网格(om);
	me = f_surface_创建实例(me ? me : S_节点数据::g_me_球体);

	f_ob_set数据槽数量(ob, 1);
	f_ob_set数据(ob, me);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质());
	f_ob_set线宽(ob, 1.0, 0);
	f_ob_set颜色2(ob, ob->m_颜色, 0);
	f_mesh_set绘制内存属性(f_ob_getMesh(ob, 0), {});
	f_mesh_计算包围盒(f_ob_getMesh(ob, 0));

	return me;
}

S_Mesh* f_node_虚拟体_设置平面虚拟网格(S_物体* ob, S_Mesh* me) {
	auto om = f_ob_getMesh(ob);
	if (om) f_surface_销毁网格(om);
	me = f_surface_创建实例(me ? me : S_节点数据::g_me_平面);

	f_ob_set数据槽数量(ob, 1);
	f_ob_set数据(ob, me);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质());
	f_ob_set线宽(ob, 1.0, 0);
	f_ob_set颜色2(ob, ob->m_颜色, 0);
	f_mesh_set绘制内存属性(f_ob_getMesh(ob, 0), {});
	f_mesh_计算包围盒(f_ob_getMesh(ob, 0));

	return me;
}

S_Mesh* f_node_虚拟体_设置胶囊虚拟网格(S_物体* ob, S_Mesh* me) {
	auto om = f_ob_getMesh(ob);
	if (om) f_surface_销毁网格(om);

	me = f_surface_创建实例(me ? me : S_节点数据::g_me_胶囊);

	f_ob_set数据槽数量(ob, 1);
	f_ob_set数据(ob, me);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质());
	f_ob_set线宽(ob, 1.0, 0);
	f_ob_set颜色2(ob, ob->m_颜色, 0);
	f_mesh_set绘制内存属性(f_ob_getMesh(ob, 0), {});
	f_mesh_计算包围盒(f_ob_getMesh(ob, 0));

	return me;
}

S_Mesh* f_node_虚拟体_设置铰链轴虚拟网格(S_物体* ob, S_Mesh* me) {
	auto om = f_ob_getMesh(ob);
	if (om) f_surface_销毁网格(om);

	me = f_surface_创建实例(me ? me : S_节点数据::g_me_铰链轴);

	f_ob_set数据槽数量(ob, 1);
	f_ob_set数据(ob, me);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质());
	f_ob_set线宽(ob, 1.0, 0);
	f_ob_set颜色2(ob, ob->m_颜色, 0);
	f_mesh_set绘制内存属性(f_ob_getMesh(ob, 0), {});
	f_mesh_计算包围盒(f_ob_getMesh(ob, 0));

	return me;
}

S_Mesh* f_node_虚拟体_设置模型虚拟网格(S_物体* ob, S_Mesh* re) {
	auto me = f_ob_getMesh(ob);
	if (me) f_surface_销毁网格(me);
	me = f_surface_创建实例(re ? re : S_节点数据::g_me_立方体);
	//me = f_surface_创建实例(re);

	f_ob_set数据槽数量(ob, 1);
	f_ob_set数据(ob, me);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线材质());
	f_ob_set线宽(ob, 1.0, 0);
	f_ob_set颜色2(ob, ob->m_颜色, 0);
	f_mesh_set绘制内存属性(f_ob_getMesh(ob, 0), {});
	f_mesh_计算包围盒(f_ob_getMesh(ob, 0));

	return me;
}



static S_Mesh* f_node_构建实例网格(E_网格预设类型 类型) {
	S_Mesh* me = nullptr;
	switch (类型) {
		case E_网格预设类型::e_网格预设_球体: {
			me = f_surface_创建实例(S_节点数据::g_me_球体, true, true, true, true, true, true);
			break;
		}
		case E_网格预设类型::e_网格预设_圆柱: {
			me = f_surface_创建实例(S_节点数据::g_me_圆柱体, true, true, true, true, true, true);
			break;
		}
		case E_网格预设类型::e_网格预设_Y轴箭头: {
			me = f_surface_创建实例(S_节点数据::g_me_虚拟体_Y箭头, true, true, true, true, true, true);
			break;
		}
		case E_网格预设类型::e_网格预设_Y轴旋转箭头: {
			me = f_surface_创建实例(S_节点数据::g_me_虚拟体_Y旋转箭头, true, true, true, true, true, true);
			break;
		}
		case E_网格预设类型::e_网格预设_十字叉: {
			me = f_surface_创建实例(S_节点数据::g_me_十字叉, true, true, true, true, true, true);
			break;
		}
	}
	assert(me);
	me->m_预设类型 = 类型;
	f_mesh_set绘制内存属性(me, {});
	return me;
}
static void f_node_构建操作对象虚拟网格(S_物体* ob, E_网格预设类型* 预设类型, uint32 num) {
	uint32 已有数量 = ob->m_DataNum;

	for (uint32 i = 0; i < 已有数量; ++i) {
		if (i >= num) {
			f_surface_销毁网格(((S_Mesh*)ob->m_Data[i]));
			ob->m_Data[i] = nullptr;
		}
		else if ( ((S_Mesh*)ob->m_Data[i])->m_预设类型 != 预设类型[i] ) {
			f_surface_销毁网格(((S_Mesh*)ob->m_Data[i]));
			
			ob->m_Data[i] = f_node_构建实例网格(预设类型[i]);
		}
	}
	f_ob_set数据槽数量(ob, num);

	for (uint32 i = 已有数量; i < num; ++i) {
		ob->m_Data[i] = f_node_构建实例网格(预设类型[i]);
	}
	
}

static void f_node_力范围虚拟体网格属性设置(S_Mesh** me, E_形状 形状, bool 关闭范围) {
	if (关闭范围) {
		switch (形状) {
			case E_形状::e_shape球体: {
				f_mesh_get网格元素绘制属性(me[0]).m_TransformMode = DEF_MESH_LINE_TRANFORMTYPEMODEL_NONE | (DEF_MESH_Tranform_Independent << 16);
				f_mesh_get网格元素绘制属性(me[1]).m_TransformMode = DEF_MESH_LINE_TRANFORMTYPEMODEL_NONE | (DEF_MESH_Tranform_Independent << 16);
				break;
			}
			case E_形状::e_shape圆柱: {
				uint32 mode = DEF_MESH_LINE_TRANFORMTYPEMODEL_Cylinder | (DEF_MESH_Tranform_Independent << 16);
				f_mesh_get网格元素绘制属性(me[0]).m_TransformMode = mode;
				f_mesh_get网格元素绘制属性(me[1]).m_TransformMode = mode;
				break;
			}
			default: return;
		}

		f_mesh_get网格元素绘制属性(me[0]).m_Scale = 1;
		f_mesh_get网格元素绘制属性(me[1]).m_Scale = 1;
	}
	else {
		f_mesh_get网格元素绘制属性(me[0]).m_Scale = 0;
		f_mesh_get网格元素绘制属性(me[1]).m_Scale = 0;
	}
}

static void f_node_力范围虚拟体网格形状(E_形状 形状, E_网格预设类型* 网格预设类型) {
	switch (形状) {
		case E_形状::e_shape球体: {
			网格预设类型[0] = E_网格预设类型::e_网格预设_球体;
			网格预设类型[1] = E_网格预设类型::e_网格预设_球体;
			break;
		}
		case E_形状::e_shape圆柱: {
			网格预设类型[0] = E_网格预设类型::e_网格预设_圆柱;
			网格预设类型[1] = E_网格预设类型::e_网格预设_圆柱;
			break;
		}
		default:
			break;
	}
}

void f_node_虚拟体_设置单向力虚拟网格(S_物体* ob, E_形状 形状, bool 关闭范围) {
	E_网格预设类型 网格预设类型[3] = { };
	网格预设类型[2] = E_网格预设类型::e_网格预设_Y轴箭头;
	f_node_力范围虚拟体网格形状(形状, 网格预设类型);
	f_node_构建操作对象虚拟网格(ob, 网格预设类型, 3);
	

	f_node_力范围虚拟体网格属性设置((S_Mesh**)ob->m_Data, 形状, 关闭范围);

	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质());
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质(), 1);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质(), 2);

	f_ob_set线宽(ob, 1.5, 2);
	f_ob_set颜色(ob, ob->m_颜色);
	f_ob_计算网格包围盒(ob);
}

void f_node_虚拟体_设置径向力虚拟网格(S_物体* ob, E_形状 形状, bool 关闭范围) {
	E_网格预设类型 网格预设类型[3] = { };
	网格预设类型[2] = E_网格预设类型::e_网格预设_十字叉;
	f_node_力范围虚拟体网格形状(形状, 网格预设类型);
	f_node_构建操作对象虚拟网格(ob, 网格预设类型, 3);


	f_node_力范围虚拟体网格属性设置((S_Mesh**)ob->m_Data, 形状, 关闭范围);

	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质());
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质(), 1);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质(), 2);

	f_ob_set线宽(ob, 1.5, 2);
	f_ob_set颜色(ob, ob->m_颜色);
	f_ob_计算网格包围盒(ob);
}

void f_node_虚拟体_设置旋转力虚拟网格(S_物体* ob, E_形状 形状, bool 关闭范围) {
	E_网格预设类型 网格预设类型[4] = { };
	网格预设类型[2] = E_网格预设类型::e_网格预设_Y轴箭头;
	网格预设类型[3] = E_网格预设类型::e_网格预设_Y轴旋转箭头;
	f_node_力范围虚拟体网格形状(形状, 网格预设类型);
	f_node_构建操作对象虚拟网格(ob, 网格预设类型, 4);


	f_node_力范围虚拟体网格属性设置((S_Mesh**)ob->m_Data, 形状, 关闭范围);

	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质());
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质(), 1);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质(), 2);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质(), 3);

	f_ob_set线宽(ob, 1.5, 2);
	f_ob_set线宽(ob, 1.5, 3);
	f_ob_set颜色(ob, ob->m_颜色);
	f_ob_计算网格包围盒(ob);
}

void f_node_虚拟体_设置涡流力虚拟网格(S_物体* ob, E_形状 形状, bool 关闭范围) {
	E_网格预设类型 网格预设类型[3] = { };
	网格预设类型[2] = E_网格预设类型::e_网格预设_Y轴旋转箭头;
	f_node_力范围虚拟体网格形状(形状, 网格预设类型);
	f_node_构建操作对象虚拟网格(ob, 网格预设类型, 3);


	f_node_力范围虚拟体网格属性设置((S_Mesh**)ob->m_Data, 形状, 关闭范围);
	
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质());
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质(), 1);
	f_ob_set材质(ob, f_NodeCtx_get基本光照线段材质(), 2);

	f_ob_set线宽(ob, 1.5, 2);
	f_ob_set颜色(ob, ob->m_颜色);
	f_ob_计算网格包围盒(ob);
}

void f_node_虚拟体_设置力范围网格大小(S_物体* ob, E_形状 形状, vec2 半径, vec2 高度) {
	auto* m1 = f_ob_getMesh(ob, 0);
	auto* m2 = f_ob_getMesh(ob, 1);
	f_mesh_get网格元素绘制属性(m1).m_Scale = 半径.x;
	f_mesh_get网格元素绘制属性(m2).m_Scale = 半径.y;
	f_mesh_get网格元素绘制属性(m1).m_YScale = 高度.x;
	f_mesh_get网格元素绘制属性(m2).m_YScale = 高度.y;
}


void f_node_create骨骼虚拟体网格(S_物体* m_骨架, bool 骨干) {
	m_骨架->m_颜色 = {200, 200, 200, 255};
	
	auto* F骨节mesh = f_surface_创建实例(f_buf_getGlobal().g_骨节圆形, true, true, true, false, true, true);
	F骨节mesh->m_线宽 = 3.0;

	//骨骼mesh->m_深度控制 = { 0.0001f, 0.01f };
	auto* 骨节mesh = f_surface_创建实例(f_buf_getGlobal().g_骨节圆形, true, true, true, false, true, true);
	骨节mesh->m_线宽 = 2.5;

	


	auto 网格属性 = f_init_MeshTranform();
	//网格属性.m_TransformMode = DEF_MESH_LINE_TRANFORMTYPEMODEL_CenterZoom;


	if (骨干) {
		auto* F骨骼mesh = f_surface_创建实例(f_buf_getGlobal().g_骨头锥形, true, true, true, false, true, true);
		auto* 骨骼mesh = f_surface_创建实例(f_buf_getGlobal().g_骨头锥形, true, true, true, false, true, true);
		骨骼mesh->m_线宽 = 2.5;


		f_mesh_set绘制内存属性(F骨骼mesh, {});
		f_mesh_set绘制内存属性(骨骼mesh, {});

		f_ob_set数据槽数量(m_骨架, 4);

		f_ob_set数据(m_骨架, F骨骼mesh, 2);
		f_ob_set数据(m_骨架, 骨骼mesh, 3);

		f_ob_set材质(m_骨架, f_NodeCtx_get基本平直面光照材质(), 2);
		//f_ob_set线宽(m_骨架, 2.0, 2);
		f_ob_set材质(m_骨架, f_NodeCtx_get基本光照面轮廓材质(), 3);
		f_ob_set线宽(m_骨架, 3.4, 3);


		f_mesh_gen网格元素绘制属性(骨骼mesh, 1);
		f_mesh_gen网格元素绘制属性(F骨骼mesh, 1);


		f_mesh_set网格元素绘制属性(F骨骼mesh, 网格属性);
		f_mesh_set网格元素绘制属性(骨骼mesh, 网格属性);


		f_ob_set颜色2(m_骨架, m_骨架->m_颜色, m_骨架->m_实例ID, 2);
		f_ob_set颜色2(m_骨架, S_RGBA8UI{ 1, 1, 1, 255 }, m_骨架->m_实例ID, 3);


		f_mesh_计算包围盒(F骨骼mesh);
		f_mesh_计算包围盒(骨骼mesh);


		F骨节mesh->m_显示 = false;
		骨节mesh->m_显示 = false;


		网格属性.m_ZMove = DEF_骨骼朝向.z;
	}
	else {
		f_ob_set数据槽数量(m_骨架, 2);
	}
	//骨节mesh->m_深度控制 = { 0.0001f, 0.01f };
	f_mesh_set绘制内存属性(F骨节mesh, {});
	f_mesh_set绘制内存属性(骨节mesh, {});

	f_ob_set数据(m_骨架, F骨节mesh, 0);
	f_ob_set数据(m_骨架, 骨节mesh, 1);

	
	
	f_ob_set材质(m_骨架, f_NodeCtx_get基本光照面材质(), 0);
	//f_ob_set线宽(m_骨架, 2.0, 0);
	f_ob_set材质(m_骨架, f_NodeCtx_get基本光照面轮廓材质(), 1);
	f_ob_set线宽(m_骨架, 3.4, 1);
	
	
	 
	f_mesh_gen网格元素绘制属性(F骨节mesh, 1);
	f_mesh_gen网格元素绘制属性(骨节mesh, 1);
	

	f_mesh_set网格元素绘制属性(F骨节mesh, 网格属性);
	f_mesh_set网格元素绘制属性(骨节mesh, 网格属性);
	


	f_ob_set颜色2(m_骨架, m_骨架->m_颜色, m_骨架->m_实例ID, 0);
	f_ob_set颜色2(m_骨架, S_RGBA8UI{ 1, 1, 1, 255 }, m_骨架->m_实例ID, 1);
	//f_surface_计算三角形边相邻面索引(骨骼mesh);
	//f_surface_计算三角形边相邻面索引(骨节mesh);
	if (S_节点数据::g_物体全局渲染模式 & E_物体视口显示::e_OVS_面) {
		m_骨架->m_视口显示模式 = 
			E_物体视口显示::e_OVS_轮廓
			| E_物体视口显示::e_OVS_面
			| E_物体视口显示::e_OVS_边
			| E_物体视口显示::e_OVS_边框;
	}
	else {
		m_骨架->m_视口显示模式 =
			E_物体视口显示::e_OVS_轮廓
			| E_物体视口显示::e_OVS_面;
	}
	m_骨架->m_视口显示模式 |= (m_骨架->m_视口显示模式 << 16);
	

	f_mesh_计算包围盒(F骨节mesh);
	f_mesh_计算包围盒(骨节mesh);

	
}


S_物体* f_node_create创建十字叉虚拟体(S_设备环境& ctx) {
	S_物体* 虚拟体 = f_node_创建虚拟体(ctx);
	虚拟体->m_颜色 = { 0,0,0,255 };

	f_ob_set数据槽数量(虚拟体, 1);
	f_ob_set数据(虚拟体, f_surface_创建实例(S_节点数据::g_me_十字叉, true, true, true, false, true, true));
	f_ob_set材质(虚拟体, f_NodeCtx_get基本光照线段材质());
	f_ob_set线宽(虚拟体, 2.0, 0);
	f_ob_set颜色2(虚拟体, 虚拟体->m_颜色, 0);
	f_mesh_set绘制内存属性(f_ob_getMesh(虚拟体, 0), {});
	f_mesh_计算包围盒(f_ob_getMesh(虚拟体, 0));

	return 虚拟体;
}

